package com.ktvme.controller;


import com.ktvme.dto.ClusterDTO;
import com.ktvme.result.Result;
import com.ktvme.service.ClusterService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;

@RestController
@RequestMapping("/BDMobieOps/clusters")
@Slf4j
@Tag(name = "集群相关接口")
public class ClusterController {

    @Autowired
    private ClusterService clusterService;

    @PostMapping
    @Operation(summary = "创建集群")
    public Result createCluster(@RequestBody ClusterDTO clusterDTO){
        log.info("创建集群：{}",clusterDTO);
        clusterService.save(clusterDTO);
        return Result.success();
    }

    @DeleteMapping
    @Operation(summary = "删除集群")
    public Result deleteCluster(@PathParam("clusterId") String clusterId){
        log.info("删除集群：{}",clusterId);
        clusterService.delete(clusterId);
        return Result.success();
    }

    @PostMapping("/update")
    @Operation(summary = "更新集群")
    public Result updateCluster(@RequestBody ClusterDTO clusterDTO,String clusterId){
        log.info("集群id：{}，更新集群：{}",clusterId,clusterDTO);
        clusterService.update(clusterDTO, Integer.valueOf(clusterId));
        return Result.success();
    }

    @GetMapping("/list")
    @Operation(summary = "查询集群列表")
    public Result listCluster(){
        return Result.success(clusterService.list());
    }
}